package com.eagletsoft.mmproj.ui;

import com.eagletsoft.mmproj.R;
import com.eagletsoft.mmproj.ui.widget.CirclePageIndicator;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


public class UserGuideActivity extends BaseActivity {
	
	ImagePagerAdapter mAdapter;
	ViewPager mPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_guide);
		
		mAdapter = new ImagePagerAdapter(getSupportFragmentManager());
		
		mPager = (ViewPager)findViewById(R.id.pager);
		mPager.setAdapter(mAdapter);
		
		CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
		indicator.setViewPager(mPager);
	}
	
	public static class ImagePagerAdapter extends FragmentPagerAdapter {
		
		public final static Integer[] IMAGE_RES_IDS = new Integer[] { R.drawable.guide1,
            R.drawable.guide2, R.drawable.guide3,R.drawable.start_page };
		
		private int mCount = IMAGE_RES_IDS.length;
		
		public ImagePagerAdapter(FragmentManager fm) {
			super(fm);
		}
		
		@Override
		public Fragment getItem(int position) {
			return GuideItemFragment.newInstance(IMAGE_RES_IDS[position % IMAGE_RES_IDS.length]);
		}

		@Override
		public int getCount() {
			return mCount;
		}
		
		public void setCount(int count) {
			if (count > 0 && count <= 10) {
				mCount = count;
				notifyDataSetChanged();
			}
		}
	}
}
